/*
赋值规则
https://golang.google.cn/ref/spec#Assignability

隐式转换
双方应该具有相同的基础类型，而且其中至少有一个不是命名类型(至少有一个是未命名变类型)。

参考文章
https://studygolang.com/articles/20086
https://gfw.go101.org/article/value-conversions-assignments-and-comparisons.html
*/

package main

import (
	"fmt"
)

const G_num = 100

type MyInt int
type MyMap map[string]int

type MyStrings0 []string
type MyStrings1 MyStrings0

type Type0 struct {
	id int
}
type Type1 struct {
	id int
}

type Type2 Type0
type Type3 Type1

func main() {
	var x MyInt
	var y int
	fmt.Println(x, y)
	//x = y	// Cannot use 'y' (type int) as the type MyInt
	x = G_num // 常量支持隐式转换

	var m1 MyMap
	var m2 map[string]int
	fmt.Println(m1, m2)
	m1 = m2 // 不会报错
	m2 = m1 // 不会报错

	var myStrings []string
	var myStrings0 MyStrings0
	var myStrings1 MyStrings1
	fmt.Println(myStrings, myStrings0, myStrings1)
	myStrings0 = myStrings
	//myStrings0 = myStrings1  // Cannot use 'myStrings1' (type MyStrings1) as the type MyStrings0

	var type0 Type0
	var type1 Type1
	var type2 Type2
	var type3 Type3
	var type4 struct {
		id int
	}
	fmt.Println(type0, type1, type2, type3, type4)
	//type2 = type0  // Cannot use 'type0' (type Type0) as the type Type2
	//type2 = type1
	//type2 = type3
	type0 = type4
	type1 = type4
	type2 = type4
	type3 = type4
}
